package com.example.diskfilesystem;

import config.Config;
import com.example.diskfilesystem.disk.Disk;
import com.example.diskfilesystem.disk.DiskInitializer;
import com.example.diskfilesystem.disk.FATManager;
import com.example.diskfilesystem.directory.DirectoryManager;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.stage.Stage;
import java.io.IOException;

public class DiskFileSystem extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            // 初始化磁盘系统
            Disk disk = new Disk(Config.DISK_FILE);
            DiskInitializer.initialize(disk);

            FATManager fat = new FATManager(disk);
            fat.load();

            DirectoryManager dm = new DirectoryManager(disk, fat);

            // 创建并显示UI
            DiskFileSystemUI ui = new DiskFileSystemUI(disk, fat, dm);
            Scene scene = new Scene(ui.getRootPane(), 1000, 700);

            primaryStage.setTitle("磁盘文件系统模拟器");
            primaryStage.setScene(scene);
            primaryStage.show();

        } catch (IOException e) {
            e.printStackTrace();
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("启动错误");
            alert.setHeaderText("无法初始化文件系统");
            alert.setContentText(e.getMessage());
            alert.showAndWait();
        }
    }
}